package com.vvv.method;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author vvv
 * @date 2023-10-16 15 00
 * discription
 */
public class ReentrantLockDemo01 {
    public static final ReentrantLock lock = new ReentrantLock();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            try {
                lock.lockInterruptibly();
            } catch (InterruptedException e) {
                e.printStackTrace();
                return;
            }
            try {
                System.out.println("获得了锁");
            } finally {
                lock.unlock();
            }
        }, "t1");

        System.out.println("main线程获得锁");
        lock.lock();
        t1.start();
        t1.interrupt();
    }
}
